package middle;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

/**
 * 1833. 雪糕的最大数量
 */
public class MaxIceCream {

    public static int[] stringToIntegerArray(String input) {
        input = input.trim();
        input = input.substring(1, input.length() - 1);
        if (input.length() == 0) {
            return new int[0];
        }

        String[] parts = input.split(",");
        int[] output = new int[parts.length];
        for(int index = 0; index < parts.length; index++) {
            String part = parts[index].trim();
            output[index] = Integer.parseInt(part);
        }
        return output;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while ((line = in.readLine()) != null) {
            int[] costs = stringToIntegerArray(line);
            line = in.readLine();
            int coins = Integer.parseInt(line);

            int ret = new Solution().maxIceCream(costs, coins);

            String out = String.valueOf(ret);

            System.out.print(out);
        }
    }

    static class Solution {
        public int maxIceCream(int[] costs, int coins) {
            Arrays.sort(costs);
            int size = 0;
            for (int cost:costs){
                if (coins>=cost){
                    size++;
                    coins-=cost;
                }else {
                    break;
                }
            }
            return size;
        }
    }
}
